{{#if (or (eq runtime "bun") (eq runtime "node") (eq runtime "none"))}}
{{#if (and (ne backend "self") (includes frontend "next"))}}
import dotenv from "dotenv";

dotenv.config({
	path: "../../apps/server/.env",
});

{{/if}}
import { drizzle } from "drizzle-orm/libsql";
import { createClient } from "@libsql/client";

const client = createClient({
  url: process.env.DATABASE_URL || "",
  {{#if (eq dbSetup "turso")}}
  authToken: process.env.DATABASE_AUTH_TOKEN,
  {{/if}}
});

export const db = drizzle({ client });
{{/if}}

{{#if (eq runtime "workers")}}
{{#if (eq dbSetup "d1")}}
import { drizzle } from "drizzle-orm/d1";
import { env } from "cloudflare:workers";

export const db = drizzle(env.DB);
{{else}}
import { drizzle } from "drizzle-orm/libsql";
import { env } from "cloudflare:workers";
import { createClient } from "@libsql/client";

const client = createClient({
  url: env.DATABASE_URL || "",
  {{#if (eq dbSetup "turso")}}
  authToken: env.DATABASE_AUTH_TOKEN,
  {{/if}}
});

export const db = drizzle({ client });
{{/if}}
{{/if}}
